<template>
	<view>
		<view class=" u-p-r-30 u-p-l-30 u-m-t-20" >
			<view class="content wrap">
				<u-form :model="form" ref="uForm"  :rules="rules">
					<u-form-item label="门店*" label-width="150" prop="weight">
						<u-input v-model="form.storeName"  placeholder="请输入门店"/>
					</u-form-item>
					<u-form-item label="排班日期*" label-width="150" prop="weight">
						<u-input v-model="form.plantDate" placeholder="选择排班日期" type="select" @click="getT()"/>
					</u-form-item>
					<u-form-item label="员工姓名*" label-width="150" prop="weight">
						<u-input v-model="form.empName"  placeholder="请输入员工姓名"/>
					</u-form-item>
					<u-form-item label="职务*" label-width="150" prop="weight">
						<u-input v-model="form.position" type="select"  @click="getO()" placeholder="请选择职务"/>
					</u-form-item>
					<u-row>
						<u-col span="6" text-align="center">
							<u-form-item label="上班时间*" label-width="150" prop="weight">
								<view>
									<u-input v-model="form.startTime" type="select" @click="getStartTime()" />
								</view>
							</u-form-item>
						</u-col>
						<u-col span="6" text-align="center">
							<u-form-item label="下班时间*" label-width="150" prop="weight">
								<view>
									<u-input v-model="form.endTime" type="select" @click="getEndTime()" />
								</view>
							</u-form-item>
						</u-col>	
					</u-row>
				</u-form>
				<view>
					<u-calendar v-model="show" mode="date" max-date="2070-01-01" @change="change"></u-calendar>
				</view>
				<button @click="submitMdpb">提交</button>
				
				<view>
					<u-select v-model="show2" :list="olist" @confirm="confirm2"></u-select>
				</view>
				<view>
					<u-select v-model="show3" :list="startList" @confirm="confirm3"></u-select>
				</view>
				<view>
					<u-select v-model="show4" :list="endList" @confirm="confirm4"></u-select>
				</view>
			</view>
			<view>
				<u-toast ref="uToast" />
			</view>
			
		</view>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				setMentiontime:'',
				dataList: [],
				dataList2: [],
				show2:false,
				show3:false,
				show4:false,
				show:false,
				popupShow:false,
				areanumberlist:[],
				form: {
					storeName:'',
					plantDate:'',
					week:'',
					samePeriodBusiness:'',
					tableMaker:'',
					estimatedTurnover:'',
					estimatedTimeFrame:'',
					estimatedWorkingHours:''
				},
				olist:[
					{
						value:"店长",
						label:"店长"
					},
					{
						value:"店助",
						label:"店助"
					},{
						value:"全职",
						label:"全职"
					},{
						value:"兼职",
						label:"兼职"
					}
					
				],
				startList:[
					{
						value:"08:00",
						label:"8点"
					},
					{
						value:"08:30",
						label:"8点30分"
					},{
						value:"09:00",
						label:"9点"
					},{
						value:"09:30",
						label:"9点30分"
					},{
						value:"10:00",
						label:"10点"
					},{
						value:"10:30",
						label:"10点30"
					},{
						value:"11:00",
						label:"11点"
					},{
						value:"11:30",
						label:"11点30分"
					},{
						value:"12:00",
						label:"12点"
					},
					{
						value:"12:30",
						label:"12点30分"
					},{
						value:"13:00",
						label:"13点"
					},{
						value:"13:30",
						label:"13点30分"
					},{
						value:"14:00",
						label:"14点"
					},{
						value:"14:30",
						label:"14点30分"
					},{
						value:"15:00",
						label:"15点"
					},{
						value:"15:30",
						label:"15点30分"
					},{
						value:"16:00",
						label:"16点"
					},{
						value:"16:30",
						label:"16点30分"
					},{
						value:"17:00",
						label:"17点"
					},{
						value:"17:30",
						label:"17点30分"
					},{
						value:"18:00",
						label:"18点"
					},{
						value:"18:30",
						label:"18点30分"
					},{
						value:"19:00",
						label:"19点"
					},{
						value:"19:30",
						label:"19点30分"
					},{
						value:"20:00",
						label:"20点"
					},{
						value:"20:30",
						label:"20点30分"
					},{
						value:"21:00",
						label:"21点"
					},{
						value:"21:30",
						label:"21点30分"
					},{
						value:"22:00",
						label:"22点"
					},
					{
						value:"22:30",
						label:"22点30分"
					},{
						value:"23:00",
						label:"23点"
					},{
						value:"23:30",
						label:"23点30分"
					},{
						value:"24:00",
						label:"24点"
					}
				],
				endList:[
					{
						value:"08:00",
						label:"8点"
					},
					{
						value:"08:30",
						label:"8点30分"
					},{
						value:"09:00",
						label:"9点"
					},{
						value:"09:30",
						label:"9点30分"
					},{
						value:"10:00",
						label:"10点"
					},{
						value:"10:30",
						label:"10点30"
					},{
						value:"11:00",
						label:"11点"
					},{
						value:"11:30",
						label:"11点30分"
					},{
						value:"12:00",
						label:"12点"
					},
					{
						value:"12:30",
						label:"12点30分"
					},{
						value:"13:00",
						label:"13点"
					},{
						value:"13:30",
						label:"13点30分"
					},{
						value:"14:00",
						label:"14点"
					},{
						value:"14:30",
						label:"14点30分"
					},{
						value:"15:00",
						label:"15点"
					},{
						value:"15:30",
						label:"15点30分"
					},{
						value:"16:00",
						label:"16点"
					},{
						value:"16:30",
						label:"16点30分"
					},{
						value:"17:00",
						label:"17点"
					},{
						value:"17:30",
						label:"17点30分"
					},{
						value:"18:00",
						label:"18点"
					},{
						value:"18:30",
						label:"18点30分"
					},{
						value:"19:00",
						label:"19点"
					},{
						value:"19:30",
						label:"19点30分"
					},{
						value:"20:00",
						label:"20点"
					},{
						value:"20:30",
						label:"20点30分"
					},{
						value:"21:00",
						label:"21点"
					},{
						value:"21:30",
						label:"21点30分"
					},{
						value:"22:00",
						label:"22点"
					},
					{
						value:"22:30",
						label:"22点30分"
					},{
						value:"23:00",
						label:"23点"
					},{
						value:"23:30",
						label:"23点30分"
					},{
						value:"24:00",
						label:"24点"
					}
				],
				rules: {
					weight: [
						{ 
							required: true,
							message: '请输入重量', 
							trigger: 'blur',
						}
					],
				}
			}
		},
		onLoad(open) {
			//#ifdef H5 || APP-PLUS
			this.flex = 'u-flex'
			//#endif
			
			console.log(open)
			this.form.storeName =  decodeURIComponent(decodeURIComponent(open.storeName))
			this.form.plantDate = open.plantDate.substr(0,10)
			
			
		},
		// created(){
		// 	this.form.storeName = this.$route.query.storeName;
		// 	this.form.plantDate = this.$route.query.plantDate
		// },
		onShow() {
			// this.refresh()
		},
		onPullDownRefresh() {
			this.refresh()
			uni.stopPullDownRefresh()
		},
		methods: {
			getO(){
				
				this.show2 = true
			},
			confirm2(e) {
				this.form.position = e[0].value
			},
			confirm3(e) {
				this.form.startTime = e[0].value
			},
			confirm4(e) {
				this.form.endTime = e[0].value
			},
			change(e) {
				this.form.plantDate = e.result
				const weekdays = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
				const weekday = new Date(this.form.plantDate).getDay();
				this.form.week = weekdays[weekday] ;
			},
			onInput(){
				var num1 = parseFloat(this.form.estimatedTurnover) || 0; // 获取第一个数，如果为空则默认为0
				        var num2 = parseFloat(this.form.estimatedTimeFrame) || 1; // 获取第二个数，如果为空则默认为0
				        var result = num1 / num2; // 简单的加法运算，你可以根据需要更改运算方式
				        this.form.estimatedWorkingHours = result.toFixed(2);
			},
		
			submitMdpb() {
				let that = this
				this.$refs.uForm.validate(valid => {
					if (valid) {
						console.log('验证通过');
						
						uni.showLoading({
							title: '正在提交'
						})
						this.$http.post('/rest/pb/addPlant',{
						},{
							params: that.form,
							header: {
								'Authorization' :uni.getStorageSync('token'),
							}
						}).then(res => {
							uni.hideLoading()
							if(res.data.code == 200) {
								this.$refs.uToast.show({
									title: '操作成功',
									type: 'success'
								})
								this.$Router.push({
									name: 'mdPb'
								})
							} else {
								this.$refs.uToast.show({
									title: res.data.message,
									type: 'error'
								})
							}
						})
					} else {
						console.log('验证失败');
					}
				});
			},
			toguihua(item){
				this.$Router.push({ 
					name: 'storage_out_plan',
					params: { 
						getUnitId:item.getUnitId,
						getLocationId:item.getLocationId,
						setMentiontime:this.setMentiontime
					},
				})
			},
			yihedanmingxi(item){
				let storageOutNumbers = []
				for(let item1 of this.dataList) {
					if(item.getUnitId == item1.getUnitId && item.getLocationId == item1.getLocationId){
						for(let item2 of item1.list2) {
							if(item2.id == item.id){
								for(let item3 of item2.list2) {
									storageOutNumbers.push(item3.storageOutNumber)
								}
							}
						}
					}
				}
				this.$http.post('/rest/storageOut/apporderdetailslist?storageOutNumbers='+storageOutNumbers,{
				},{
					params: {
					},
					header: {
						'Authorization' :uni.getStorageSync('token'),
					}
				}).then(res => {
					this.dataList2 = res.data.data
					this.popupShow = true
				})
			},
			weihedanmingxi(storageOutNumber){
				let storageOutNumbers = []
				storageOutNumbers.push(storageOutNumber)
				this.$http.post('/rest/storageOut/apporderdetailslist?storageOutNumbers='+storageOutNumbers,{
				},{
					params: {
					},
					header: {
						'Authorization' :uni.getStorageSync('token'),
					}
				}).then(res => {
					this.dataList2 = res.data.data
					this.popupShow = true
				})
			},
			checkboxChange(e){
				console.log(e)
			},
			totaskss(item){
				let storageOutNumbers = []
				let privatecarCarnumbers = ''
				let areanumber = ''
				let getUnit = ''
				let getLocation = ''
				for(let item1 of this.dataList) {
					if(item.getUnitId == item1.getUnitId && item.getLocationId == item1.getLocationId){
						privatecarCarnumbers = item1.privatecarCarnumbers
						areanumber = item1.areanumber
						getUnit = item1.getUnit
						getLocation = item1.getLocation
						for(let item2 of item1.list2) {
							if(item2.id == item.id){
								for(let item3 of item2.list2) {
									storageOutNumbers.push(item3.storageOutNumber)
								}
							}
						}
					}
				}
				let storage_out_task = {}
				storage_out_task.storageOutNumber = storageOutNumbers
				storage_out_task.privatecarCarnumbers = privatecarCarnumbers
				storage_out_task.areanumber = areanumber
				storage_out_task.getUnit = getUnit
				storage_out_task.getLocation = getLocation
				uni.setStorageSync('storage_out_task', storage_out_task);
				this.$Router.push({ 
					name: 'storage_out_task_mark'
				})
			},
			totask(item){
				let storageOutNumbers = []
				let privatecarCarnumbers = ''
				let areanumber = ''
				let getUnit = ''
				let getLocation = ''
				storageOutNumbers.push(item.storageOutNumber)
				for(let item1 of this.dataList) {
					if(item.getUnitId == item1.getUnitId && item.getLocationId == item1.getLocationId){
						privatecarCarnumbers = item1.privatecarCarnumbers
						areanumber = item1.areanumber
						getUnit = item1.getUnit
						getLocation = item1.getLocation
					}
				}
				let storage_out_task = {}
				storage_out_task.storageOutNumber = storageOutNumbers
				storage_out_task.privatecarCarnumbers = privatecarCarnumbers
				storage_out_task.areanumber = areanumber
				storage_out_task.getUnit = getUnit
				storage_out_task.getLocation = getLocation
				uni.setStorageSync('storage_out_task', storage_out_task);
				this.$Router.push({ 
					name: 'storage_out_task'
				})
			},
		
			getT(){
				this.show = true
			},
			getStartTime(){
				this.show3 = true
			},
			getEndTime(){
				this.show4 = true
			},
			
			
			
			 
			
			
			
			refresh(){
				uni.showLoading({
					title: '加载中...'
				})
				this.$http.post('/rest/pb/pbList',{
				},{
					params: {
						setMentiontime: this.setMentiontime
					},
					header: {
						'Authorization' :uni.getStorageSync('token'),
					}
				}).then(res => {
					this.dataList = res.data.data
					uni.hideLoading()
				})
				
			},
		},
	}
</script>
<style lang="scss">
	.huanhang{
		word-break:break-all;
	}
</style>